package com.roin.learn.activiti.utils;

import com.roin.learn.activiti.entity.Position;
import com.roin.learn.activiti.entity.User;
import com.roin.learn.activiti.service.PositionService;

import java.util.LinkedHashMap;
import java.util.List;

public class BeanMcUtil {
    private static LinkedHashMap<Integer,String> postionMap;

    public static void setUserMcList(List<User> users){
        for (User dto : users) {
            setUserMc(dto);
        }
    }
    public static void setUserMc(User dto){
        if (postionMap==null) {
            PositionService positionService = (PositionService) SpringContextUtil.getBean("positionService");
            List<Position> positions = positionService.getAll();
            postionMap = new LinkedHashMap<>();
            for (Position p : positions) {
                postionMap.put(p.getId(),p.getPositionMc());
            }
        }
        dto.setPositionMc(postionMap.get(dto.getPositionId()));
    }
}
